﻿<!DOCTYPE html>
<html>

<head>
    <title>maptalks example</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.5.1/dist/leaflet.css">


    <style>
        html,
        body,
        #map {
            height: 100%;
            padding: 0;
            margin: 0;
        }
    </style>
</head>

<body>
    <div id="map"></div>

    <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://unpkg.com/leaflet@1.5.1/dist/leaflet.js"></script>
    <script src="../../build/mapv.js"></script>
    <script>

        var map = L.map('map').setView([39.910843952376,116.41348403785], 12);

        L.tileLayer('http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png', {
            'subdomains': ['a', 'b', 'c', 'd', 'e']
        }).addTo(map);

        $.get('../data/od-xierqi.txt', function (rs) {
            var data = [];
            var timeData = [];

            rs = rs.split("\n");
            console.log(rs.length);
            var maxLength = 0;
            for (var i = 0; i < rs.length; i++) {
                var item = rs[i].split(',');
                var coordinates = [];
                if (item.length > maxLength) {
                    maxLength = item.length;
                }
                for (j = 0; j < item.length; j += 2) {
                    // var coord = trans.untransform(new maptalks.Point(Number(item[j]), Number(item[j + 1])),1);
                    //coordinates.push([coord.x,coord.y]);
                    var x = Number(item[j]) / 20037508.34 * 180;
                    var y = Number(item[j + 1]) / 20037508.34 * 180;
                    y = 180 / Math.PI * (2 * Math.atan(Math.exp(y * Math.PI / 180)) - Math.PI / 2);
                    if (x == 0 || y == NaN) {
                        continue;
                    }
                    coordinates.push([x, y]);
                    timeData.push({
                        geometry: {
                            type: 'Point',
                            coordinates: [x, y]
                        },
                        count: 1,
                        time: j
                    });
                }
                data.push({
                    geometry: {
                        type: 'LineString',
                        coordinates: coordinates
                    }
                });

            }

            var dataSet = new mapv.DataSet(data);

            var options = {
                strokeStyle: 'rgba(53,57,255,0.5)',
                // globalCompositeOperation: 'lighter',
                shadowColor: 'rgba(53,57,255,0.2)',
                shadowBlur: 3,
                lineWidth: 3.0,
                draw: 'simple'
            }

            var mapvLayer = mapv.leafletMapLayer(dataSet, options).addTo(map);


            var dataSet = new mapv.DataSet(timeData);

            var options = {
                fillStyle: 'rgba(255, 250, 250, 0.2)',
                globalCompositeOperation: "lighter",
                size: 1.5,
                animation: {
                    stepsRange: {
                        start: 0,
                        end: 100
                    },
                    trails: 3,
                    duration: 5,
                },
                draw: 'simple'
            }

            var mapvLayer = mapv.leafletMapLayer(dataSet, options).addTo(map);
        });

    </script>
</body>

</html>